/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package presistencia;

import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 * @Data 16/04/12 
 * @author Marcelo Paiva (Meticore)
 */
public class GravaDao {

    
    
    
    public GravaDao() {
    
    }
 
    
    public static void  encerraChamado(int num_os){
       
       int num = num_os; 
      
      
       //GravaDao.num_os = num_os; 
        
      ReparoDao reparo = new ReparoDao();
        
  
      String [][]reparos = sysmanutencao.SysManutencaoView.getReparos();
      
      for(int cont = 0 ; cont< reparos.length ; cont++){
          

          if(reparos[cont][0] != null){
              
         
          
          System.out.println(cont);
          
          Session session = DaoHibernate.getSession();
          Transaction tx = session.beginTransaction();
         
          reparo.setNum_os(num);
          reparo.setTipo_chamado(reparos[cont][0]);
          reparo.setItem(reparos[cont][1]);
          reparo.setDesc_tarefa(reparos[cont][2]);
          reparo.setData_hora_inicio(reparos[cont][3]);
          reparo.setData_hora_final(reparos[cont][4]);
          reparo.setCod_manutentor(Integer.parseInt(reparos[cont][5]));
          reparo.setPlaqueta(reparos[cont][6]);
          
          session.save(reparo); 
          
          tx.commit();
     
          session.close(); 
          
          }else{
              
              cont = 50;
              
          }
      }   
  
   }
    
    
    public static void mudaStatus(int num_os){
        
         int num = num_os; 
        
        Session session = DaoHibernate.getSession();
        ChamadoDao chamado = (ChamadoDao) session.load(ChamadoDao.class,num) ;
        
         
         Transaction tx = session.beginTransaction();
         
         chamado.setStatus("F");
       
         session.update(chamado); 
          
          tx.commit();
     
          session.close();
        
        
    }
            
            
    
}
